package com.chushouya.order.constants;

import com.general.framework.core.enums.IEnum;
import com.general.framework.core.lang.Lists;
import com.chushouya.order.dto.admin.order.OrderQuery;

import java.util.List;
import java.util.Objects;

/**
 * 订单列表查询状态枚举
 * 0全部 1 新订单 2 待确认 3 已取消 4 待收货 5 待质检 6 待接单 7 待确认 8 待上门 9 待议价 10 待打款 11 已完成 12 已关闭  13 运输中
 */
public enum OrderListLogicStatusEnum implements IEnum<Integer> {
    allCount(0,  "全部",   Lists.emptyList()),
    newOrder(1,  "新订单", Lists.asList(OrderStatusEnum.NEW_ORDER.value())),
    visitConfirm(15,  "上门待确认", Lists.asList(OrderStatusEnum.WAIT_CHECK.value())),
    expressConfirm(2,  "邮寄待确认", Lists.asList(OrderStatusEnum.WAIT_CHECK.value())),
    cancel(3,  "已取消", Lists.asList(OrderStatusEnum.CANCELLED.value(),OrderStatusEnum.CLERK_CANCEL.value(),OrderStatusEnum.CLOSED.value(),OrderStatusEnum.TIMEOUT.value())),
//    kefCancel(4,  "客服取消", Lists.asList(OrderStatusEnum.CLOSED.value())),
//    clerkCancel(14,  "业务员取消", Lists.asList(OrderStatusEnum.CLERK_CANCEL.value(),OrderStatusEnum.BACKOUT_AUDITING.value(),OrderStatusEnum.BACKOUT_CLOSED.value())),
    //待发货
    waitPickup(12,  "待取件", Lists.asList(OrderStatusEnum.WAIT_PICKUP.value())),
    transport(13,  "运输中", Lists.asList(OrderStatusEnum.WAIT_RECEIVE.value())),
    waitAccept(6,  "待接单", Lists.asList(OrderStatusEnum.WAIT_ACCEPT.value())),
    waitVisit(8,  "待上门", Lists.asList(OrderStatusEnum.WAIT_VISIT.value())),
    waitCheck(5,  "待质检", Lists.asList(OrderStatusEnum.WAIT_QUALITY.value())),
    waitBargain(9,  "待议价", Lists.asList(OrderStatusEnum.WAIT_BARGAIN.value())),
    waitPay(10,  "待打款", Lists.asList(OrderStatusEnum.WAIT_PAY.value())),
    waitReturn(18,  "待退货", Lists.asList(OrderStatusEnum.WAIT_RETURN.value())),
    complete(11,  "已完成", Lists.asList(OrderStatusEnum.COMPLETE.value())),;

    private Integer logicStatus;

    private String logicStatusName;

    private List<Integer> statusList;

    OrderListLogicStatusEnum(Integer logicStatus, String logicStatusName, List<Integer> orderStatusList) {
        this.logicStatus = logicStatus;
        this.logicStatusName = logicStatusName;
        this.statusList = orderStatusList;
    }

    public static OrderListLogicStatusEnum get(Integer logicStatus) {
        for (OrderListLogicStatusEnum thisEnum : OrderListLogicStatusEnum.values()) {
            if (Objects.equals(thisEnum.logicStatus, logicStatus)) {
                return thisEnum;
            }
        }
        return OrderListLogicStatusEnum.allCount;
    }

    public static OrderListLogicStatusEnum getEnum(String logicStatusName) {
        for (OrderListLogicStatusEnum thisEnum : OrderListLogicStatusEnum.values()) {
            if (Objects.equals(thisEnum.name(), logicStatusName)) {
                return thisEnum;
            }
        }
        return OrderListLogicStatusEnum.allCount;
    }

    public static OrderListLogicStatusEnum[] clerkValues() {
        return new OrderListLogicStatusEnum[]{
                allCount,
//                clerkCancel,
                waitAccept,
                waitVisit,
                waitPay,
                complete
        };
    }

    public OrderQuery buildQuery(OrderQuery query) {
        query.setOrderStatusList(this.statusList());
        return query;
    }

    public List<Integer> statusList() {
        return statusList;
    }

    @Override
    public Integer value() {
        return logicStatus;
    }

    @Override
    public String named() {
        return logicStatusName;
    }
}
